﻿using MultiLang;
using System;
using System.Collections.Generic;

namespace Rsdn.Janus
{
    /// <summary>
    /// Макрос для вставки цитаты.
    /// </summary>
    [TextMacrosProvider]
    internal sealed class CitationMacrosProvider : ITextMacrosProvider
    {
        private static string GetValue(IServiceProvider serviceProvider)
        {
            string[] citations = Config.Instance.TagLine.CitationTagConfig.Citations;
            if (citations == null || citations.Length < 1)
            {
                return ml.ml_string(229, "<нет никакой цитаты>");
            }

            if (Config.Instance.TagLine.CitationTagConfig.QueryType == CitationQueryType.Random)
            {
                Random rnd = new Random();
                int cp = rnd.Next(citations.Length);
                return citations[cp];
            }

            if (Config.Instance.TagLine.CitationTagConfig.LastPosition >= citations.Length)
            {
                Config.Instance.TagLine.CitationTagConfig.LastPosition = 0;
            }
            return citations[Config.Instance.TagLine.CitationTagConfig.LastPosition];
        }

        public IEnumerable<ITextMacros> CreateTextMacroses()
        {
            return new[]
                       {
                           new TextMacros(
                               "citation",                            //MLHIDE
                               ml.ml_string(1431, "Цитата"), //Citation
                               GetValue
                               )
                       };
        }
    }
}
